# ifndef __FileTypeInfo_H_
# define __FileTypeInfo_H_

struct map_t;

# include "LoadStatus.h"

class CMapLoader;
class CMapSaver;

enum {
	ftiDefault      = 0x01,
	ftiImportExport = 0x02,
	ftiRenderer     = 0x04,
	ftiDontMapFile  = 0x08,

	ftiWpts         = 0x10,
	ftiTracks       = 0x20,
	ftiRoutes       = 0x40,
	ftiWTR          = (ftiWpts | ftiTracks | ftiRoutes),
};

class CFileTypeInfo {
  public:
	typedef CMapLoader * (* pfCreateLoader_t) ();
	typedef CMapSaver  * (* pfCreateSaver_t)  ();

	CFileTypeInfo (
		pfCreateLoader_t _pfCreateLoader, pfCreateSaver_t _pfCreateSaver,
		const char * _strClass,	const char * _strExt, const char * _strFilter,
		DWORD _dwFlags
	);

	const pfCreateLoader_t m_pfCreateLoader;
	const pfCreateSaver_t  m_pfCreateSaver;
	const char * const m_strClass;
	std::vector<string_t> m_vecExts;
	string_t m_strFilter;

	const DWORD m_dwFlags;

	const size_t m_cOrdinal;

	// The linked list of creators.
	CFileTypeInfo * m_pNext;
	static CFileTypeInfo * s_pFirst;

  private:
	bool m_bEnableSave;

	friend class CMapLoader;

	static size_t s_cMaxIndex;

	CFileTypeInfo * FindSaverInfo () const;
	static const CFileTypeInfo * GetDefaultSaverInfo ();

  public:
	bool IsSaveEnabled () const {return m_bEnableSave;}
	void EnableSave (bool _bEnable);

	//
	// The utilities for map loaders/savers (registration, search etc).
	//

	static void GetOpenFileFilter (string_t & _strFilter, DWORD _dwRequiredFlagsFilter);

	static CMapLoader * CreateLoader (
		const char * _pData, size_t _cFileSize, const char * _pFileName,
		const CFileTypeInfo ** _ppSaverInfo, DWORD & _dwFlags
	);
	//
	static void ShowOpenFile (bool _bRemoveOldMap);
	static void ShowOpenFile (bool _bRemoveOldMap, bool _bWait, map_t & _map, DWORD _dwRequiredFlagsFilter, const char * _strDefaultName = NULL);

	static void ShowSaveFile ();

	static void InitImportMenu (HMENU _hMenu);
	static void ShowImportFile (size_t _cIndex);

	static HMENU InitExportMenu (HMENU _hMenu);
	static void ShowExportFile (size_t _cIndex);

	static CFileTypeInfo * FindSaverInfoByClass (const char * _strClass);

	static void Sort ();
};

# endif // __FileTypeInfo_H_